public class Queue {

    private class Node {
        int val;
        Node next;

        Node() {}
        Node(int val) {
            this.val = val;
            this.next = null;
        }
    }

    private Node front;
    private Node rear;
    private int len;
    private int size;

    public Queue(int size) {
        this.size = size;
        this.len = 0;
    }

    public void push(int val) {
        if (this.len >= this.size) {
            System.out.println("warning: 队列已满");
            return;
        }
        Node node = new Node(val);
        if (this.len == 0) {
            this.front = node;
            this.rear = node;
        } else {
            this.rear.next = node;
            this.rear = node;
            this.rear.next = null;
        }
        this.len ++;
    }

    public Node pop() {
        Node node;
        if (this.len == 0) {
            System.out.println("warning: 队列已空");
            return null;
        } else {
            node = this.front;
            this.front = node.next;
        }
        this.len --;
        return node;
    }

    public int len() {
        return this.len;
    }

    public void show() {
        Node node = this.front;
        for (int i = 0; i < this.len; i ++) {
            System.out.printf("-%d-", node.val);
            node = node.next;
        }
        System.out.println();
    }

    public static void main(String[] args) {
        System.out.println("Queue starting...");

        Queue queue = new Queue(10);
        int[] queue_list = {3, 5, 4, 8, 2, 6, 1};

        for (int i = 0; i < queue_list.length; i ++) {
            queue.push(queue_list[i]);
            queue.show();
        }
        queue.pop();

        queue.show();
    }
}
